﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class CustomerController : Controller
    {
        //
        // GET: /Customer/

        public ActionResult Index()
        {
            return View();
        }

        public string SaveCustomer(DTO.CustomerDTO CustomerDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.RegisterCustomer(CustomerDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public string UpdateCustomer(DTO.CustomerDTO CustomerDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.UpdateCustomer(CustomerDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public string DeleteCustomer(string id)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.DeleteCustomerByID(id, "");
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public ContentResult GetAllCustomers()
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.CustomerDTO> listCustomer = chinaerService.GetAllCustomers("");
            string jsonResult = Helper.JsonHelper.GetJson(listCustomer, listCustomer.Count);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }

    }
}
